/**
 * 
 */
package com.td.framework.webmanager.xtbm.action;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.td.framework.common.AbstractAction;
import com.td.framework.webmanager.bmxx.service.BmxxService;
import com.td.framework.webmanager.domain.AppsysBmxx;
import com.td.framework.webmanager.domain.AppsysXtbmBean;
import com.td.framework.webmanager.xtbm.service.XtbmService;
import com.opensymphony.xwork2.Action;

/**
 * 
 *  Title:系统编码权限Action
 *  Description: 处理系统编码操作
 *  Copyright: Copyright (c) 2008 
 *  Company 北京水软科技有限公司
 * @version 1.0
 */
public class XtbmAction  extends AbstractAction implements Action{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 547418446077794273L;
	private XtbmService xtbmService = null;//系统编码业务层接口;
	private BmxxService bmxxService = null;//部门信息业务层接口;
	private List<AppsysXtbmBean> xtbmList = null;// 系统编码List;
	private List<AppsysBmxx> bmxxList = null;// 部门信息list;
	private String [] xtbms = null;//系统编码组
	private String oldXtbm = ""; //权限中原有系统编码
	private String defaultBmbh = "";//部门编号
	private String [] bmbms = null;//部门编码
	private String yhbh = "";//用户编号;
	private int yhlb = 1 ;//用户类别;
	private String urlFlag = "";// 区分字段,授权是区分是点击下一步还是完成;
	private String target = "";// 返回参数;
	/**
	 * toDo:子系统编码列表;
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String listXtbmqx()
	{
		xtbmList = xtbmService.findXtbmBeanByYhbh(yhbh, yhlb);
		target = "xtbmList";
		if(urlFlag.equals("tree"))
		{
			target = "xtbmTree";
			List<AppsysXtbmBean> tempList = xtbmList;
			xtbmList=new ArrayList();
			for (Iterator iterator = tempList.iterator(); iterator.hasNext();) {
				AppsysXtbmBean tempXtbmBean = (AppsysXtbmBean) iterator.next();
				if(tempXtbmBean.getIsChecked()==1)
				{
					xtbmList.add(tempXtbmBean);
				}
			}
		}
		return target ;
	}
	/**
	 * toDo:与权限结合的部门列表
	 * @return target;
	 */
	public String listQxBmxxTree()
	{
		bmxxList = bmxxService.findBmxxByYhbh(yhbh,defaultBmbh, yhlb, xtbms[0],0);
		target = "qxBmxxTree";
		return target;
	}
	/**
	 * toDo:保存用户子系统权限;
	 * @return target
	 */
	public String changeXtbmqx()
	{
		boolean flag = false;
		flag = xtbmService.changeXtbmqx(xtbms, yhbh, yhlb,oldXtbm);
		if(flag==true&&urlFlag.equals("next")&&xtbms!=null)
		{
			target = "nextRight";
		}
		else
		{
			if(flag==true)
			{
				this.handleMessage("info", "操作成功,请继续操作!");
			}
			else
			{
				this.handleMessage("info", "操作失败,请重新操作!");
			}
			target = "xtbmQxSuccess";
			xtbmList = xtbmService.findXtbmBeanByYhbh(yhbh, 1);
		}
		return target;
	}
	/**
	 * toDo:保存用户子系统所辖部门权限;
	 * @return target
	 */
	public String changeBmqx()
	{
		if(xtbmService.changeBmqx(xtbms[0], yhbh, yhlb, bmbms))
		{
			this.handleMessage("info", "操作成功,请继续操作!");
		}
		else
		{
			this.handleMessage("info", "操作失败,请重新操作!");
		}
		bmxxList = bmxxService.findBmxxByYhbh(yhbh,defaultBmbh, yhlb, xtbms[0],0);
		target = "bmqxSuccess";
		return target;
	}
	/**
	 * toDo:get
	 * @return xtbmService
	 */
	public XtbmService getXtbmService() {
		return xtbmService;
	}
	/**
	 * toDo:set
	 * @param xtbmService 
	 */
	public void setXtbmService(XtbmService xtbmService) {
		this.xtbmService = xtbmService;
	}
	/**
	 * toDo:get
	 * @return bmxxService
	 */
	public BmxxService getBmxxService() {
		return bmxxService;
	}
	/**
	 * toDo:set
	 * @param bmxxService 
	 */
	public void setBmxxService(BmxxService bmxxService) {
		this.bmxxService = bmxxService;
	}
	/**
	 * toDo:get
	 * @return xtbmList
	 */
	public List<AppsysXtbmBean> getXtbmList() {
		return xtbmList;
	}
	/**
	 * toDo:set
	 * @param xtbmList 
	 */
	public void setXtbmList(List<AppsysXtbmBean> xtbmList) {
		this.xtbmList = xtbmList;
	}
	/**
	 * toDo:get
	 * @return bmxxList
	 */
	public List<AppsysBmxx> getBmxxList() {
		return bmxxList;
	}
	/**
	 * toDo:set
	 * @param bmxxList 
	 */
	public void setBmxxList(List<AppsysBmxx> bmxxList) {
		this.bmxxList = bmxxList;
	}
	/**
	 * toDo:get
	 * @return xtbms
	 */
	public String[] getXtbms() {
		return xtbms;
	}
	/**
	 * toDo:set
	 * @param xtbms 
	 */
	public void setXtbms(String[] xtbms) {
		this.xtbms = xtbms;
	}
	/**
	 * toDo:get
	 * @return oldXtbm
	 */
	public String getOldXtbm() {
		return oldXtbm;
	}
	/**
	 * toDo:set
	 * @param oldXtbm 
	 */
	public void setOldXtbm(String oldXtbm) {
		this.oldXtbm = oldXtbm;
	}
	/**
	 * toDo:get
	 * @return bmbms
	 */
	public String[] getBmbms() {
		return bmbms;
	}
	/**
	 * toDo:set
	 * @param bmbms 
	 */
	public void setBmbms(String[] bmbms) {
		this.bmbms = bmbms;
	}
	/**
	 * toDo:get
	 * @return yhbh
	 */
	public String getYhbh() {
		return yhbh;
	}
	/**
	 * toDo:set
	 * @param yhbh 
	 */
	public void setYhbh(String yhbh) {
		this.yhbh = yhbh;
	}
	/**
	 * toDo:get
	 * @return urlFlag
	 */
	public String getUrlFlag() {
		return urlFlag;
	}
	/**
	 * toDo:set
	 * @param urlFlag 
	 */
	public void setUrlFlag(String urlFlag) {
		this.urlFlag = urlFlag;
	}
	/**
	 * toDo:get
	 * @return target
	 */
	public String getTarget() {
		return target;
	}
	/**
	 * toDo:set
	 * @param target 
	 */
	public void setTarget(String target) {
		this.target = target;
	}
	/**
	 * toDo:get
	 * @return yhlb
	 */
	public int getYhlb() {
		return yhlb;
	}
	/**
	 * toDo:set
	 * @param yhlb 
	 */
	public void setYhlb(int yhlb) {
		this.yhlb = yhlb;
	}
	/**
	 * toDo:get
	 * @return defaultBmbh
	 */
	public String getDefaultBmbh() {
		return defaultBmbh;
	}
	/**
	 * toDo:set
	 * @param defaultBmbh 
	 */
	public void setDefaultBmbh(String defaultBmbh) {
		this.defaultBmbh = defaultBmbh;
	}
}
